home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 1.6 KB | 78 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // BCPool.h
- //
- // This file contains the declaration of the heap storage management class.
-
- #ifndef BCPOOL_H
- #define BCPOOL_H 1
-
- #include <stddef.h>
- #include "BCType.h"
-
- // Class denoting a pool of memory stored on the heap
-
- class BC_CPool {
- public:
-
- BC_CPool(size_t chunkSize);
- ~BC_CPool();
-
- void* Allocate(size_t);
- void Deallocate(void*, size_t);
-
- void Preallocate(BC_Index numberOfChunks);
- void ReclaimUnusedChunks();
- void PurgeUnusedChunks();
-
- size_t ChunkSize() const
- {return fChunkSize;}
- BC_Index TotalChunks() const
- {return (NumberOfDirtyChunks() + NumberOfUnusedChunks());}
- BC_Index NumberOfDirtyChunks() const;
- BC_Index NumberOfUnusedChunks() const;
-
- protected:
-
- struct BC_SElement {
- BC_SElement* fNextElement;
- BC_SElement() : fNextElement(0) {}
- };
-
- struct BC_SChunk {
- BC_SChunk* fPreviousSizedChunk;
- BC_SChunk* fNextSizedChunk;
- BC_SChunk* fNextChunk;
- BC_Index fElementSize;
- BC_Index fNumberOfElements;
- BC_SElement* fNextElement;
- BC_SChunk()
- : fPreviousSizedChunk(0),
- fNextSizedChunk(0),
- fNextChunk(0),
- fElementSize(0),
- fNumberOfElements(0),
- fNextElement(0) {}
- };
-
- BC_SChunk* fHead;
- BC_SChunk* fUnusedChunks;
- size_t fChunkSize;
- size_t fUsableChunkSize;
-
- BC_SChunk* GetChunk(size_t s);
-
- static size_t Align(size_t);
-
- private:
-
- BC_CPool(const BC_CPool&) {}
- void operator=(const BC_CPool&) {}
- void operator==(const BC_CPool&) {}
- void operator!=(const BC_CPool&) {}
-
- };
-
- #endif
-